Wiki Scrapbook Bookmarklet 2.0

 

In late August an anonymous genius posted on the Oddmuse Wiki a much-improved way to capture tidbits from web pages with a single click, which my 2012 initial-version Wiki Scrapbook Bookmarklet did via a complex method that required a server-side module. The new approach uses the "Comments_on" feature of Oddmuse. To begin, simply:

  • create a bookmark
  • copy/paste the below javascript function into the "Location" (URL) field of that bookmark
  • edit the variables "wikiBase" and "scrapPage" to be the target location on an Oddmuse wiki (like the ZhurnalyWiki) for storing the copy/paste scrap into, and save the bookmark. (The version below defaults to the ZhurnalyWiki's "SandBox" page.)

To use it, when browsing a web page just highlight a section of interesting text (up to a few paragraphs), then click on the bookmarklet. The URL, page title, and highlighted selection will be appended to the target page of the bookmarklet. (Note that for this process to work on ZhurnalyWiki you likely will need already to have accepted a cookie that permits editing. See page Editor Password for instructions on how to do that, if you aren't a spammer.)

javascript:void((function() {
    var wikiBase = 'http://zhurnaly.com/cgi-bin/wiki';
    var scrapPage = 'SandBox';
    var urlOfWebPage = document.location;
    var titleOfWebPage = document.title;
    var linkToWebPage =  '[' + urlOfWebPage + ' ' + titleOfWebPage + ']';
    var selectedText = window.getSelection();
    var capturedText = linkToWebPage + '\n\n' + selectedText;
    var nw = window.open('','','toolbar=0,resizable=1,scrollbars=1,status=1,width=750,height=500');
    var nwd = nw.document;

    nwd.body.innerHTML =
	'<div class="comment">' +
    	'  <form method="post" action="http://localhost/cgi-bin/wiki.pl/Public" enctype="multipart/form-data" accept-charset="utf-8" class="comment">' +
    	'    <p>' +
    	'      <label for="title">Title:</label>' +
    	'      <input name="title" id="title">' + '<br/>' +
    	'      <textarea name="aftertext" rows="10" cols="78" id="aftertext">' +
    	'      </textarea>' +
    	'    </p>' +
    	'    <p>' +
    	'      <span class="username">' +
    	'	<label for="username">Username:</label>' +
    	'	<input name="username" size="20" maxlength="50" id="username" type="text">' +
    	'      </span>' + '<br/>' +
    	'      <span class="homepage">' +
    	'	<label for="homepage">Homepage URL:</label>' +
    	'	<input name="homepage" size="40" maxlength="100" id="homepage" type="text">' +
    	'      </span>' +
    	'    </p>' +
    	'    <p>' +
    	'      <input name="Save" value="Save" accesskey="s" type="submit">' +
    	'      <input name="Preview" value="Preview" accesskey="p" type="submit">' +
    	'    </p>' +
    	'  </form>' +
    	'</div>';

    nwd.getElementById('title').setAttribute('value', scrapPage);
    nwd.getElementById('aftertext').value = capturedText;
    var f = nwd.forms[0];

    f.setAttribute('action', wikiBase);
    
    f.submit();
})())

Brilliant — many thanks to whoever created this neat hack!

(cf. Scrapbook Bookmarklet Version 0.1 (2010-12-26), Wiki Scrapbook Bookmarklet (2012-01-11), ...) - ^z - 2013-10-06